﻿//建筑公共部位通用下拉框的获取
var uri = document.location.search;//接收页面传值
var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
var P_ReportNumber = uri.substr(i);//截取问号前面的值
//定位坐标
var wapx = 0;
var wapy = 0;

$(function () {

    //判断状态去取消按钮
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/selectbyP_ReportNumberss",
        data: {
            P_ReportNumber: P_ReportNumber
        },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    if (data.T_State != 1) {
                        $("#jbSub").remove();
                        $("#Clickontheget").remove();
                    }
                }
            }
        }
    })
    //下拉框获取
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Dictionary/GetDictionaryList",
        async: false,
        data: {
            Dmenuid: [14, 15, 16, 17, 18, 19, 20, 21, 22]
        },
        success: function (data, status) {
            $("option").remove();
            $(data).each(function (i, obj) {
                $(obj).each(function (j, item) {
                    switch (item.Dmenuid) {
                        case 14:
                            $("#T_StructureID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 15:
                            $("#T_TypesID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 16:
                            $("#T_FacadeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 17:
                            $("#T_CommonalityID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 18:
                            $("#T_ElevatorID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 19:
                            $("#T_SupplyID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 20:
                            $("#T_WaterID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 21:
                            $("#T_HeatingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 22:
                            $("#T_EntranceID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                    }
                })
            })

        }
    })
    //数据回填
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Facility/SelectByid",
        data: { P_ReportNumber: P_ReportNumber },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    $("#T_Buildingafew").val(data.T_Buildingafew)
                    $("#T_Location").val(data.T_Location)
                    $("#T_LocationAddress").val(data.T_LocationAddress)
                    var lc = data.T_Location.split(',')
                    wapx = lc[0];
                    wapy = lc[1];

                    $("#T_StructureID").val(data.T_StructureID)
                    $("#T_TypesID").val(data.T_TypesID)
                    $("#T_FacadeID").val(data.T_FacadeID)
                    $("#T_CommonalityID").val(data.T_CommonalityID)
                    $("#T_ElevatorID").val(data.T_ElevatorID)
                    $("#T_SupplyID").val(data.T_SupplyID)
                    $("#T_WaterID").val(data.T_WaterID)
                    $("#T_HeatingID").val(data.T_HeatingID)
                    $("#T_EntranceID").val(data.T_EntranceID)
                    $("#T_Else").val(data.T_Else)
                }
            }
        }
    })
})
//建筑公共部位状况的数据添加
function insertBuilding() {
    var T_Buildingafew = $("#T_Buildingafew").val();
    var T_Location = $("#T_Location").val();                                   //定位坐标
    var T_LocationAddress = $("#T_LocationAddress").val();                     //定位地址
    var T_StructureID = $("#T_StructureID option:checked").attr("value");      //房屋结构编号
    var T_TypesID = $("#T_TypesID option:checked").attr("value");              //房屋类型编号
    var T_FacadeID = $("#T_FacadeID option:checked").attr("value");            //外立面装饰编号
    var T_CommonalityID = $("#T_CommonalityID option:checked").attr("value");  //公共部位装修编号
    var T_ElevatorID = $("#T_ElevatorID option:checked").attr("value");        //电梯编号 
    var T_SupplyID = $("#T_SupplyID option:checked").attr("value");            //供气编号
    var T_WaterID = $("#T_WaterID option:checked").attr("value");              //供水编号
    var T_HeatingID = $("#T_HeatingID option:checked").attr("value");          //供暖编号
    var T_EntranceID = $("#T_EntranceID option:checked").attr("value");        //门禁编号
    var T_Else = $("#T_Else").val();                                           //其他
    var parms = {
        T_ReportNumber: P_ReportNumber,
        T_Buildingafew: T_Buildingafew,
        T_Location: T_Location,
        T_LocationAddress: T_LocationAddress,
        T_StructureID: T_StructureID,//房屋结构编号
        T_TypesID: T_TypesID,//房屋类型编号
        T_FacadeID: T_FacadeID,//外立面装饰编号
        T_CommonalityID: T_CommonalityID,//公共部位装修编号
        T_ElevatorID: T_ElevatorID,//电梯编号 
        T_SupplyID: T_SupplyID,//供气编号
        T_WaterID: T_WaterID,//供水编号
        T_HeatingID: T_HeatingID,//供暖编号
        T_EntranceID: T_EntranceID,//门禁编号
        T_Else: T_Else	     //其他
    }
    $.ajax({
        type: "post",
        url: ApiUrl + "api/Facility/Postinsert",
        data: parms,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }
            }
        }
    })

}
//确定定位
function getLocation() {
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/UpdateT_StartDateAndT_EndDate",
        data: { P_ReportNumber: P_ReportNumber },
        //async: false,
        success: function (data, status) {
            if (data)
            {
                layer.msg('定位确认成功!', { icon: 1, time: 1000 });
            }
        }
    })

}